#!/bin/bash

# 定义变量
#PYTHON_VERSION="3.11.10"
#PYTHON_SRC_URL="https://www.python.org/ftp/python/${PYTHON_VERSION}/Python-${PYTHON_VERSION}.tgz"
INSTALL_DIR="/poc/compose/python311"

# 下载 Python 源码
#echo "正在下载 Python ${PYTHON_VERSION} 源码..."
#wget -q ${PYTHON_SRC_URL} -O Python-${PYTHON_VERSION}.tgz

# 解压源码
#echo "正在解压源码..."
#tar -xzf Python-${PYTHON_VERSION}.tgz
#cd Python-${PYTHON_VERSION}

dnf groupinstall "Development Tools" -y
# 安装依赖
yum install openssl-devel sqlite-devel bzip2-devel gdbm-devel xz-devel tk-devel libuuid-devel nss-devel libffi-devel -y

# 配置编译选项
echo "正在配置编译选项..."
./configure \
  --prefix=${INSTALL_DIR} \
  --enable-optimizations \
  --with-ensurepip=install

# 编译源码
echo "正在编译源码..."
make -j$(nproc)

# 安装 Python
echo "正在安装 Python 到 ${INSTALL_DIR}..."
make install

# 验证安装
echo "验证安装结果..."
${INSTALL_DIR}/bin/python3 --version
${INSTALL_DIR}/bin/pip3 --version

# 清理临时文件
#echo "清理临时文件..."
#cd ..
#rm -rf Python-${PYTHON_VERSION} Python-${PYTHON_VERSION}.tgz

echo "Python 编译安装完成！"


